package demo;

import java.util.Locale;

public class Test {

    public static void swap2(MyValue m1, MyValue  m2) {
        int tmp = m1.val;
        m1.val = m2.val;
        m2.val = tmp;
    }

    public static void main(String[] args) {
        MyValue myValue1 = new MyValue();
        myValue1.val = 10;
        MyValue myValue2 = new MyValue();
        myValue2.val = 20;
        System.out.println(myValue1.val + " " + myValue2.val);
        swap2(myValue1, myValue2);
        System.out.println(myValue1.val + " " + myValue2.val);
    }

    public static void swap1(int m1, int m2) {
        int tmp = m1;
        m1 = m2;
        m2 = tmp;
    }

    public static void main1(String[] args) {
        MyValue myValue1 = new MyValue();
        myValue1.val = 10;
        MyValue myValue2 = new MyValue();
        myValue2.val = 20;
        System.out.println(myValue1.val + " " + myValue2.val);
        swap1(myValue1.val, myValue2.val);
        System.out.println(myValue1.val + " " + myValue2.val);
    }

    /*public static void main(String[] args) {
        String s = "hello world";
        int[] arr = new int[127];
        for (int i = 0; i < s.length(); i++) {
            arr[s.charAt(i)]++;
        }
        for (int i = 0; i < s.length(); i++) ;
        {
            if (1 == arr[s.charAt(i)]) {
                return i;
            }
        }
    }*/

/*
    public static void main3(String[] args) {
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = sb1;
        sb1.append(" ");
        sb1.append("hello");
        sb2.append(" world");
        System.out.println(sb2);
        System.out.println(sb1);
        System.out.println(sb1 == sb2);
        System.out.println(sb1.equals(sb2));
        System.out.println(sb1.charAt(0));
        System.out.println(sb1.charAt(1));
        System.out.println(sb2.charAt(1));
        System.out.println(sb1.length());
        System.out.println(sb2.length());
        System.out.println(sb1.capacity());
        System.out.println(sb2.capacity());//capacity可以获取字符串中的长度为多少
        sb1.setCharAt(0, 'Z');
        System.out.println(sb1);
        System.out.println(sb1.insert(0, "hello bit!!!!!!!   "));//insert可以在设置在字符串下标什么位置上进行插入要插入的数据
        System.out.println(sb1.indexOf("hello"));
        System.out.println(sb1.lastIndexOf("hello"));
        System.out.println(sb1.deleteCharAt(0));//指定删除下标为多少的字符
        System.out.println(sb1.delete(0, 8));//指定删除区间内的字符

        String str = sb1.substring(0, 6);   //索取字符串中期间内的字符，如何返回
        System.out.println(str);

        StringBuilder sb3 = new StringBuilder("hello world");
        System.out.println(sb3.reverse());  //reverse可以逆序字符串
    }

    public static void main2(String[] args) {
        long start = System.currentTimeMillis();
        String s = " ";
        for (int i = 0; i < 10000; i++) {
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer();
        for (int i = 0; i < 10000; i++) {
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for (int i = 0; i < 10000; i++) {
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }


    public static void main1(String[] args) {
        String str = " hello%$$%@#$%WROLD 哈哈哈 ";
        System.out.println(str.toUpperCase());//toUpperCase只转换字符串中的字母
        System.out.println(str.toLowerCase());//toLowerCase只转换字符串中的字母
        System.out.println("======================");
        String str1 = "helloworld";
        String str2 = "   ifgg   gjgjg  gjgn  gg              ";
        System.out.println(str1.substring(5));  //从那部分开始截取
        System.out.println(str1.substring(4, 7));  //从指定位置开始，指定位置结束来获取字符串中的数据，在java中为[ ）;
        System.out.println(str2);
        System.out.println(str2.trim());  //使用srim可以把字符串开头与结尾的空格省略
    }
*/

    /*public static void main10(String[] args) {
        String str = "name=zhangsan&age=18";
        String[] arr = str.split("&");
        for (int i = 0; i < arr.length; i++) {
            String[] temp = arr[i].split("=");
            //System.out.println(tmp[i]);
            System.out.println(temp[0] + " = " + temp[1]);
        }
    }

    public static void main(String[] args) {
        String str = "name=zhangsan&age=18";
        String[] arr = str.split("&");
        for (String x : arr) {
            String[] temp = x.split("=");
            for (String y : temp) {
                System.out.println(y);
            }
        }
    }

    public static void main8(String[] args) {
        String str = "192.168.1.1";
        String[] arr1 = str.split("\\.");
        for (String s : arr1) {
            System.out.print(s + " ");
        }
    }

    public static void main7(String[] args) {
        String str = "hello world hello bit";
        String[] arr1 = str.split(" ");
        String[] arr2 = str.split(" ", 2);//limit意思是拆出两部分
        String[] arr3 = str.split(" ", 3);//limit意思是拆出两部分
        *//*for (int i = 0; i <arr.length ; i++) {
            System.out.println(arr[i]);
        }*//*

        for (String x : arr1) {
            System.out.println(x);
        }
        System.out.println("========================================");
        for (String x : arr2) {
            System.out.println(x);
        }
        System.out.println("========================================");
        for (String x : arr3) {
            System.out.println(x);
        }
    }

    public static void main6(String[] args) {
        String str1 = "hello aaccccckkll";
        System.out.println(str1.replace('l', '-'));//replace是替换字符的方法
        System.out.println(str1.replaceFirst("ll", "o"));//relpaceFirst要使用String类型进行替换
        System.out.println(str1.replaceAll("cc", "bit"));
        System.out.println(str1.replaceAll("cx", "bit"));
    }

    public static void main5(String[] args) {
        String s = String.format("%d-%d-%c-%c", 2024, 18, 'c', 'b');
        String s1 = String.format("%d/%d/%d", 25, 12, 2024);
        System.out.println(s);
        System.out.println(s1);
    }

    public static void main4(String[] args) {
        String s = "hello";
        char[] ch = s.toCharArray();
        int tmp = ch.length;
        for (int i = 0; i < tmp; i++) {
            System.out.print(ch[i]);
        }
        System.out.println();
        String s1 = new String(ch);
        System.out.println(s1);
    }


    public static void main3(String[] args) {
        String str1 = "abcdef";
        String str2 = "ABCDEFHIGK";
        System.out.println(str1.toUpperCase());//（）里没有内容，直接使用字符串str1来调用toUpperCase就行
        System.out.println(str2.toLowerCase());//（）里没有内容，直接使用字符串str2来调用toLowerCase就行
    }


    public static void main2(String[] args) {
        String str1 = String.valueOf(1234); //valueOf是将数字转换为字符串
        String str2 = String.valueOf(12.34);
        String boole1 = String.valueOf(true);//valueOf是将布尔类型转换为String类型
        String boole2 = String.valueOf(false);
        String str3 = String.valueOf(new Student("hello bit", 18));
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(boole1);
        System.out.println(boole2);

    }


    public static void main1(String[] args) {
        String s = "aaabbbcccaaabbbccc";
        System.out.println(s.charAt(3));  //使用charAt来查找字符串中字符下标
        System.out.println(s.charAt(2));
        System.out.println(s.indexOf('c'));  //使用indexOf来查找字符串中第一个出现该字符的下标
        System.out.println(s.lastIndexOf('c')); //使用lastIndexOf从后往前来查找字符串中要查找字符第一次出现的下标
        System.out.println(s.indexOf('c', 10)); //使用indexOf来查找从哪个下标后面来查找第一次出现该字符的下标
        System.out.println(s.indexOf("abc")); //使用indexOf从前往后查找是否有该字符串，如果有就返回查找到该下标
        System.out.println(s.indexOf("aaa", 5));//从下标哪里从后往前查找
        System.out.println(s.lastIndexOf('c', 10));//从后往前查找，从设置的下标查找起始位置来查找
        System.out.println(s.lastIndexOf("bbb", 9));//同时，只是这边查找的是字符串
        System.out.println(s.lastIndexOf("abc"));
        System.out.println(s.lastIndexOf('g'));
        System.out.println(s.lastIndexOf('c'));
    }*/


    /*public static void main3(String[] args) {
     *//*String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("abc");
        String s4 = new String("abcdef");
        String s5 = new String("z");*//*

        String s1 = new String("abc");
        String s2 = new String("AC");
        String s3 = new String("ABc");
        String s4 = new String("abcdef");
        String s5 = new String("F");

        System.out.println(s1.compareToIgnoreCase(s2)); //-1
        System.out.println(s1.compareToIgnoreCase(s3)); //0
        System.out.println(s1.compareToIgnoreCase(s4)); //-3
        System.out.println(s5.compareToIgnoreCase(s4)); //5
    }


    public static void main2(String[] args) {
        int a = 10;
        int b = 20;
        int c = 10;
        System.out.println(a == b);
        System.out.println(a == c);


        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("world");
        String s4 = s3;
        System.out.println(s4 == s3);
        System.out.println(s1 == s2);

        System.out.println(s1.equals(s2));
        System.out.println(s4.equals(s3));
        //equals返回的是String类型
    }


    public static void main1(String[] args) {
        //1.第一种创建字符串类型
        String str1 = "hello bit";
        //2.实例化String类来创建字符串
        String str2 = new String("hello bit");
        //3.使用数组来创建字符串，让数组实例化为String类，从完成创建字符串
        *//*char[] array = {'h','e','l','l','o'};
        String str3 = new String(array);*//*
        char[] array = {'h', 'e', 'l', 'l', 'o'};
        String str3 = new String(array);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }*/


}
